home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 2 / Macwelt DVD 2.cdr / System / Internet-Utilities / macosx / News Mac 1.1.dmg / UpdateDialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-04-08  |  4.2 KB  |  103 lines

  1. import java.awt.Component;
  2. import java.awt.Container;
  3. import java.awt.Dialog;
  4. import java.awt.Dimension;
  5. import java.awt.Graphics;
  6. import java.awt.Toolkit;
  7. import java.awt.Window;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import javax.swing.ImageIcon;
  11. import javax.swing.JButton;
  12. import javax.swing.JComponent;
  13. import javax.swing.JDialog;
  14. import javax.swing.JLabel;
  15. import javax.swing.JTextArea;
  16. import javax.swing.border.EmptyBorder;
  17. import javax.swing.text.JTextComponent;
  18.  
  19. public class UpdateDialog extends JDialog implements ActionListener {
  20.    protected Container main = new Container();
  21.    protected JButton download;
  22.    protected JButton cancel;
  23.    protected boolean channelUpdate = false;
  24.    private NewsMac theParent;
  25.  
  26.    public UpdateDialog(boolean channel, NewsMac parent, String version, String descriptionText) {
  27.       super(parent, "", true);
  28.       this.theParent = parent;
  29.       ((Dialog)this).setResizable(false);
  30.       this.channelUpdate = channel;
  31.       Toolkit theKit = ((Window)this).getToolkit();
  32.       int width = 420;
  33.       int xPos = (int)(new Dimension(theKit.getScreenSize())).getWidth() / 2 - width / 2;
  34.       ((Component)this).setBounds(xPos, 160, width, 150);
  35.       JLabel logoIcon = new JLabel(new ImageIcon("newsmac.app/contents/resources/logo-icon.gif"));
  36.       ((Component)logoIcon).setBounds(24, 16, 64, 64);
  37.       JLabel title = AquaUtil.aquaLargeBoldLabel(104, 15, version, 2);
  38.       JTextArea description = new JTextArea();
  39.       ((JComponent)description).setOpaque(false);
  40.       ((JTextComponent)description).setEditable(false);
  41.       description.setLineWrap(true);
  42.       description.setWrapStyleWord(true);
  43.       ((JTextComponent)description).setText(descriptionText);
  44.       ((JComponent)description).setBorder(new EmptyBorder(0, 0, 0, 0));
  45.       description.setFont(AquaUtil.SMALL_SYSTEM);
  46.       ((Component)description).setBounds(104, 41, 284, 40);
  47.       if (this.channelUpdate) {
  48.          this.download = AquaUtil.aquaButton(306, 90, "Yes", true, false);
  49.          ((JDialog)this).getRootPane().setDefaultButton(this.download);
  50.          this.download.addActionListener(this);
  51.          this.cancel = AquaUtil.aquaButton(199, 90, "No", false, false);
  52.          this.cancel.addActionListener(this);
  53.       } else {
  54.          this.download = AquaUtil.aquaButton(306, 90, "Download", true, false);
  55.          ((JDialog)this).getRootPane().setDefaultButton(this.download);
  56.          this.download.addActionListener(this);
  57.          this.cancel = AquaUtil.aquaButton(199, 90, "Cancel", false, false);
  58.          this.cancel.addActionListener(this);
  59.       }
  60.  
  61.       this.main.add(logoIcon);
  62.       this.main.add(title);
  63.       this.main.add(description);
  64.       this.main.add(this.download);
  65.       this.main.add(this.cancel);
  66.       ((JDialog)this).getContentPane().add(this.main);
  67.    }
  68.  
  69.    public void paint(Graphics g) {
  70.       super.paint(g);
  71.    }
  72.  
  73.    public void actionPerformed(ActionEvent newEvent) {
  74.       String buttonString = newEvent.getActionCommand();
  75.       if (buttonString.equals("Download")) {
  76.          try {
  77.             NewsMacUtil.openURL("http://users.aber.ac.uk/rlp9/newsmac");
  78.          } catch (Exception var5) {
  79.             System.out.println("UpdateDialog: Open URL failed!");
  80.          }
  81.  
  82.          ((Component)this).setVisible(false);
  83.       }
  84.  
  85.       if (buttonString.equals("Yes")) {
  86.          ((Component)this).setVisible(false);
  87.  
  88.          try {
  89.             this.theParent.theEngine.loadAllChannels(true);
  90.             this.theParent.theEngine.loadAllChannels(false);
  91.             this.theParent.theEngine.applyChannelSettings();
  92.          } catch (Exception var4) {
  93.             System.out.println("UpdateDialog: Error reloading channels!+\t\n" + var4);
  94.          }
  95.       }
  96.  
  97.       if (buttonString.equals("Cancel") || buttonString.equals("No")) {
  98.          ((Component)this).setVisible(false);
  99.       }
  100.  
  101.    }
  102. }
  103.